import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_module_sale/phoenix/home/bean/home_contract_bean.dart';
import 'package:dk_flutter_module_sale/phoenix/home/bean/work_home_bean.dart';
import 'package:flutter/material.dart';
import '../bean/ui_const_bean.dart';
import 'contract_section_widget.dart';
import 'work_head_widget.dart';

class WorkContractWidget extends StatelessWidget {

  final HomeContractBean            homeContractBean;
  final UpdateModuleListBean        updateModuleBean;
  final Function(HomeContractBean)  onContractTap;

  WorkContractWidget(this.updateModuleBean,this.homeContractBean,this.onContractTap);

  @override
  Widget build(BuildContext context) {
    return buildedNewWidget(context);
  }

  Widget buildedNewWidget(BuildContext context) {
    return GestureDetector(
      onTap: (){
        print('-----点击时间线------');
        if(onContractTap!= null) {
          onContractTap(homeContractBean);
        }
      },
      child: Container(
        height:homeContractBean!=null ? (80 + homeContractBean.list.length * UIConstBean.ContractSectionH) : (80 + UIConstBean.ContractSectionH*2),   //固定80 每个单元100
        color: Colors.transparent,
        padding: const EdgeInsets.only(left: UIConstBean.LRSpace, right: UIConstBean.LRSpace, top: 10),
        child: Card(
          color: Colors.white,
          elevation: 0.0,
          margin: const EdgeInsets.only(bottom: 0),
          clipBehavior: Clip.antiAlias,
          shape: const RoundedRectangleBorder(
            side: BorderSide.none,
            borderRadius: BorderRadius.all(Radius.circular(UIConstBean.CircularRadius),
            ),
          ),
          child: Container(
              padding: const EdgeInsets.only(left: UIConstBean.InnerLRSpace,right: UIConstBean.InnerLRSpace,top: UIConstBean.InnerTopSpace),
              color: Colors.white,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: _getContractSectionWidget(),
              )
          ),
        ),
      ),
    );
  }

  List<Widget> _getContractSectionWidget() {
    List<Widget> results = List<Widget>();
    results.add(WorkHeadWidget(itemHeadTap: null, title: updateModuleBean.title,indicateType: homeContractBean!= null ? HomeHeadTitleIndicateType.HomeHeadTitleIndicateLookAtType: HomeHeadTitleIndicateType.HomeHeadTitleIndicateDefaultType,),);

    if(homeContractBean!= null) {
      for(ContractBean contractBean  in homeContractBean.list) {
        results.add(ContractSectionWidget(contractBean));
      }
    } else {
      results.add(ContractSectionWidget(null));
      results.add(ContractSectionWidget(null));
    }
    return results;
  }
}

